import os, subprocess, sys
from posixpath import join
from os import path
succ_seeds = {
    # "vi" : [0, 1, 6, 10],
    # "vi" : [6], 
    "fi" : range(0,10),
    "tr" : [1, 2, 4, 5, 6, 8, -1],
}
if __name__ == '__main__':
    src = sys.argv[1]
    trg = sys.argv[2]
    seeds = succ_seeds[src] if src in succ_seeds else range(0, 1)
    # seeds = [0]
    exp_name = 'Mar21_supervised'
    exp_id = src + '-' + trg
    exp_path = path.join('dumped', exp_name, exp_id)
    if not path.exists(exp_path):
        os.makedirs(exp_path)
    log_file_path = path.join(exp_path, 'vecmap_log.txt')
    for i in seeds:
        subprocess.run([
            "python3", "vecmap_main.py", 
            "--supervised",
            "data/crosslingual/dictionaries/" + exp_id + ".0-5000.txt",
            # "dumped/Seg04_lowcutoff/vi-en/vectors-vi.txt", "dumped/Sep06_stepcutoff/vi-en/vectors-en.txt",
            "data/word2vec." + src + ".vec", "data/word2vec." + trg + ".vec", 
            path.join(exp_path, src + ".mapped_emb.txt"), path.join(exp_path, trg + ".mapped_emb.txt"),
            "--self_learning",
            "--vocabulary_cutoff","20000",
            "--csls", "10",
            "--stochastic_initial", "1.0",
            "--verbose",
            "--validation", "data/crosslingual/dictionaries/" + exp_id + ".5000-6500.txt",
            "--log", log_file_path,
            "--seed", str(i),
            "--cuda",
        ])
        with open(log_file_path, 'a') as logfile:
            subprocess.run([
                "python3","eval_translation.py",
                path.join(exp_path, src + ".mapped_emb.txt"),
                path.join(exp_path, trg + ".mapped_emb.txt"),
                "-d", f"data/crosslingual/dictionaries/{src}-{trg}.5000-6500.txt",
                "--retrieval", "csls",
                "--cuda",
                "--seed", str(i),
            ], stdout=logfile)
